package com.vpclub.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author : leimingchao
 * @version V1.0
 * @Project: springdemo
 * @Package com.vpclub.test
 * @Description: TODO
 * @date Date : 2021年05月13日 22:46
 */
public class IOCTest3 {

    private ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext3.xml");


    @Test
    public void test() {
        System.out.println("容器启动完成。。。。。");
        Object bean = applicationContext.getBean("book");
        Object bean1 = applicationContext.getBean("book");
        System.out.println(bean == bean1);
    }

    @Test
    public void test02() {
        System.out.println("容器启动完成。。。。。");
        Object bean = applicationContext.getBean("book");
        Object bean1 = applicationContext.getBean("book");
        System.out.println(bean == bean1);
    }

    @Test
    public void test03() {
        Object bean = applicationContext.getBean("airPlane01");
        System.out.println(bean);
        System.out.println(bean.getClass());
        System.out.println("容器启动完成。。。。。");
    }

    @Test
    public void test04() {
        Object bean = applicationContext.getBean("airPlane02");
        System.out.println(bean);
        System.out.println(bean.getClass());
        System.out.println("容器启动完成。。。。。");
    }

    @Test
    public void test05() {
        Object bean = applicationContext.getBean("myFactoryBean");
        System.out.println(bean);
        Object bean2 = applicationContext.getBean("myFactoryBean");
        System.out.println(bean == bean2);
        //获取实现了FactoryBean的实例MyFactoryBean
        Object contextBean = applicationContext.getBean("&myFactoryBean");
        System.out.println(contextBean);
        System.out.println("容器启动完成。。。。。");
    }
}
